<template>
	<view class="app">
		<jnavbar :title="'维权订单列表'"></jnavbar>
		<view class="page_container">
			<view class="uni-block-list">
				<view class="order uni-flex-column" v-if="hasShow == 'none'"><u-empty text="您还没有相关的订单" mode="order"></u-empty></view>
				<view class="list uni-flex-column" v-if="hasShow == 'list'">
					<u-gap height="20"></u-gap>
					<view class="item uni-view" v-for="(order, index1) in list" :key="index1" @click="goDetail(order)">
						<view class="head sm-font uni-flex-title uni-flex-row">
							<view class="">
								<text>订单编号：</text>
								<text>{{ order.order_no }}</text>
							</view>

							<text>{{ order.statustext }}</text>
						</view>
						<block v-for="(item, index2) in order.order_commodity">
							<view class="body uni-flex-row" :key="index2">
								<view @click.stop="togoods(item.id, item.money_type)" class="img_box"><vimage class="" :src="item.commodity.master"></vimage></view>

								<view class="detail uni-flex-row ">
									<view class="uni-flex-column title">
										<text class="lg-font u-line-2">{{ item.commodity.name }}</text>
										<text v-if='item.sku' class="skuvalue u-line-1">{{ item.sku.pvs_value || '' }}</text>
										<!-- <text  class="skuvalue" v-if="item.attach_value">{{item.attach_value}}</text> -->
									</view>
									<view class="price">
										<text class="lg-font">
											<text class="sm-font" v-if="order.money_type == 1">&yen;&nbsp;</text>
											{{ item.fmoney }}x{{ item.count }}
										</text>
										<!-- <text class="num sm-font">&times;</text> -->
									</view>
									<view v-if="item.after && item.after.length > 0 && !order.show" class="button weizhi">
										<text class="cancel" @click.stop="todetail(item.after[0].id)">售后详情</text>
									</view>
								</view>
							</view>
							<!-- 	<view class="" v-if="item.attach_value">
								<text>{{ item.attach_value }}</text>
							</view> -->
							<view v-if="item.attach" v-for="(data, i) in item.attach" class="u-content-color u-flex u-row-between u-font-sm u-margin-bottom-20">
								<text>{{ data.attach_value }}</text>
								<text>&yen;&nbsp;{{ data.attach_price }}x{{ item.count }}</text>
							</view>
						</block>

						<view class="bottom uni-flex-row uni-flex-title" v-if="order.money_type == 1">
							<view class="left uni-flex-row sm-font">
								<text>运费：</text>
								<text class="price">&yen;&nbsp;{{ order.freight || '0.00' }}</text>
								<text>优惠：</text>
								<text class="price">&yen;&nbsp;{{ order.discount || '0.00' }}</text>
							</view>
						</view>
						<view class="bottom uni-flex-row uni-flex-title">
							<view class="right uni-flex-row sm-font">
								<text>
									共计
									<text class="number">{{ order.num }}</text>
									件商品,
								</text>
								<text>
									合计：
									<text class="price" v-if="order.money_type == 1">&yen;&nbsp;{{ order.allprice }}</text>
									<text class="price" v-else>{{ order.money }}</text>
								</text>
							</view>
						</view>
						<view class="button uni-flex-row" v-if="order.show">
							<text class="cancel" @click.stop="todetail(order.after_id)">售后详情</text>
							<!-- <text class="pay " @click.stop="topay(order)">立即支付</text> -->
						</view>
					</view>
				</view>
			</view>
		</view>
		<uni-login ref="Login" @callback="logincallback"></uni-login>
	</view>
</template>

<script>
import util from '@/common/util.js';
export default {
	onShareAppMessage() {
		return this.wxShare();
	},
	data() {
		return {
			list: [],
			hasShow: 'none',
			page: 1,
			size: 10
		};
	},
	onLoad() {
		// this.getlist();
	},
	onPullDownRefresh() {
		this.list = [];
		this.page = 1;
		this.getlist();
	},
	onReachBottom() {
		this.getlist();
	},
	onShow() {
		this.list = [];
		this.page = 1;
		this.getlist();
	},
	methods: {
		todetail(id) {
			// let id = item.after_commodity[0].order_after_id;
			uni.navigateTo({
				url: 'aftersale_detail?id=' + id
			});
		},
		logincallback() {},
		getlist() {
			this.$http('/order/orderRefund?page=' + this.page + '&size=10', {}, 'GET').then(res => {
				const json = res.data.msg;
				uni.stopPullDownRefresh();
				if (json.data.length > 0) {
					this.page++;
					this.hasShow = 'list';
				} else {
					this.hasShow = 'none';
				}

				let list = json.data;

				list.forEach(order => {
					order.num = 0;
					let status = order.status;
					if (order.money_type == 2) {
						status = order.mstatus;
					}
					order.statustext = util.getstatustext(status, order.order_type, order.money_type);
					order.show = true;
					order.order_commodity.forEach(item => {
						// if(order.attach&&order.attach.length>0){
						// 	item.attachlist=order.attach.filter(_=>_.commodity_id==item.id&&_.sku_id==item.sku_id)
						// }
						if (item.after && item.after.length > 0) {
							let a = item.after[0];
							if (order.after_id) {
								if (a.order_after_id != order.after_id) {
									order.show = false;
								}
							} else {
								order.after_id = a.order_after_id;
							}
						}
						item.attachlist = [];
						if (order.attach && order.attach.length > 0 && item.attach_value && item.attach_value != '') {
							order.attach.forEach(a => {
								if (item.attach_value.indexOf(a.attach_value) > -1 && item.attachlist.findIndex(_ => _.attach_value == a.attach_value) == -1) {
									item.attachlist.push(a);
								}
							});
						}
						order.num += item.count;
						item.fmoney = item.money / item.count;
						item.fmoney = item.fmoney.toFixed(2);
					});
					if (order.order_type == 3) {
						order.money = Number(order.money) - Number(order.distribution_fee);
						order.freight = order.distribution_fee.toFixed(2);
					}
					let allprice = Number(order.freight) + Number(order.money);
					order.allprice = allprice.toFixed(2);
				});

				this.list = this.list.concat(list); //追加新数据
			});
		}
	}
};
</script>

<style lang="scss">
.uni-block-list {
	// padding-top: 100rpx !important;

	.order {
		padding-top: 240rpx;
		align-items: center;

		image {
			width: 50%;
			height: 300rpx;
			margin-bottom: 100rpx;
		}

		text {
			color: #a9a9a9;
			font-size: 26rpx;
		}
	}

	.list {
		.item {
			width: 710rpx;
			margin-left: 20rpx;
			padding: 20rpx 32rpx;
			border-radius: 12rpx;

			.head {
				padding: 0 0 20rpx 0;
			}

			.body {
				padding: 20rpx 0;

				.img_box {
					width: 140rpx;
					height: 140rpx;
					margin-right: 30rpx;
					border-radius: 8rpx;
				}

				.detail {
					flex: 1;
					justify-content: space-between;
					height: 130rpx;
					position: relative;
					.title {
						justify-content: space-between;
						font-size: 36rpx;
						height: 130rpx;
						width: 320rpx;

						.skuvalue {
							color: #999;
							font-size: 26rpx;
						}
					}

					.price {
						align-self: flex-start;
						display: flex;
						flex-direction: column;
						line-height: 1;

						text:first-child {
							color: #000;
						}

						.num {
							margin-top: 20rpx;
							text-align: right;
							color: #999999;
							font-size: 24rpx;
						}
					}
				}
			}

			.bottom {
				padding: 10rpx 0;

				.left {
					width: 100%;
					justify-content: flex-end;

					.price {
						font-weight: bold;
						margin-right: 16rpx;
					}
				}

				.right {
					width: 100%;
					justify-content: flex-end;

					.number {
						font-weight: bold;
					}

					.price {
						font-weight: bold;
					}
				}
			}

			.button {
				justify-content: flex-end;
				margin-top: 18rpx;

				text {
					display: inline-block;
					text-align: center;
					font-size: 24rpx;
					line-height: 50rpx;
					// padding: 12rpx 0;

					width: 150rpx;
					border-radius: 30rpx;
					height: 50rpx;
				}

				/*cancel：取消*/
				.pay {
					color: var(--main-color);
					margin-left: 20rpx;
					border: 2rpx solid var(--main-color);
				}

				.finish {
					color: #ffffff;
					margin-left: 20rpx;
				}

				.success {
					color: #ffffff;
					margin-left: 20rpx;
				}

				.cancel {
					border: 1px solid #878787;
				}

				.refund {
					border: 1px solid #878787;
				}

				.del {
					border: 1px solid #878787;
				}

				.state {
					color: #b00606;
					width: 210rpx;
					text-align: right;
				}
			}
		}
	}
}
.weizhi {
	position: absolute;
	right: 0;
}
</style>
